{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e04bb48e-f95a-422b-8200-919e03aa8f4d",
   "metadata": {},
   "source": [
    "Chapter 05\n",
    "\n",
    "# 余弦相似性\n",
    "Book_6《数据有道》 | 鸢尾花书：从加减乘除到机器学习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f70264e0-91cf-4e6f-8bd3-bab474a9eaf8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics.pairwise import cosine_similarity\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a837b7ee-3a81-4c46-8bd8-7fa6efd564ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.array([[8, 2]])\n",
    "q = np.array([[7, 9]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7434021a-c5f4-4318-87bd-7d34e10cee33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.78705592]]\n"
     ]
    }
   ],
   "source": [
    "k_x_q = cosine_similarity(x,q)\n",
    "print(k_x_q)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
